package com.example.larou.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.example.larou.Impl.loginServiceImpl;
import com.example.larou.config.StateEnum;
import com.example.larou.entity.StateVo;
import com.example.larou.entity.User;
import com.example.larou.Impl.RegisterServiceImpl;
import com.example.larou.mapper.UserMapper;
import com.example.larou.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@ResponseBody
@Controller
public class UserController {
    @Resource
    private RegisterServiceImpl registerService;
    @Resource
    private loginServiceImpl loginService;
    @Resource
    private UserMapper userMapper;

    @PostMapping("/regist")
    public SaResult Regist(@RequestBody User user ){
        System.err.println("regist");
        return registerService.RegisterService(user);
    }
    @PostMapping("/login")
    public SaResult emailLogin(@RequestBody User user){
        System.err.println("login");
        System.err.println(user.getEmail());
        System.err.println(user.getPassword());
        System.err.println(user.getPhone_number());
        return loginService.emailLoginService(user);
    }
    @PostMapping("/exit")
    public SaResult exitLogin(){
        StpUtil.logout();
        return SaResult.ok("退出登录");
    }
    @CrossOrigin
    @PostMapping("/sendEmail")
    public SaResult sendEmail(@RequestBody StateVo stateEnum){
        System.err.println("发送邮件");
        System.err.println(stateEnum.getStateEnum());
        return loginService.sendEmail(stateEnum);
    }

}
